package com.hnevc.xiaoming.worldcupapp2018.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.hnevc.xiaoming.worldcupapp2018.R;
import com.hnevc.xiaoming.worldcupapp2018.adapter.AllAdapter;
import com.hnevc.xiaoming.worldcupapp2018.bean.AllBean;
import com.hnevc.xiaoming.worldcupapp2018.util.GetJsonfileUtil;

import java.util.ArrayList;
import java.util.List;

public class AllActivity extends AppCompatActivity {

    private ImageView back;
    private ListView lv_all;
    private List<AllBean.ItemBean> list;
    private AllAdapter allAdapter;
    private TextView pai_hang;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all);
        initView();
        initDate();

    }

    private void initDate() {
        list = new ArrayList<>();
        String json = new GetJsonfileUtil().getJson(AllActivity.this, "allqiudui.json");
        Gson gson = new Gson();
        AllBean allBean = gson.fromJson(json, AllBean.class);
        if (allBean.getItem() != null) {
            list.addAll(allBean.getItem());
        }
        allAdapter = new AllAdapter(list, AllActivity.this);
        lv_all.setAdapter(allAdapter);
    }

    private void initView() {
        back = (ImageView) findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        lv_all = (ListView) findViewById(R.id.lv_all);

        pai_hang = (TextView) findViewById(R.id.pai_hang);
        pai_hang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(AllActivity.this,MyPaiHangActivity.class));
            }
        });
    }
}
